<template>
	<view class="container">
		<TopBtn :title="'添加银行卡'"></TopBtn>
		<view class="info">
			<uni-forms ref="valiForm" :rules="rules" :label-width="120" :modelValue="valiFormData">
				<uni-forms-item label="银行卡号" required name="bankAccount">
					<uni-easyinput v-model="valiFormData.bankAccount" placeholder="请输入银行卡号" />
				</uni-forms-item>
				<uni-forms-item label="开户行" required name="openingBank">
					<uni-easyinput v-model="valiFormData.openingBank" placeholder="请输入开户行" />
				</uni-forms-item>
				<uni-forms-item label="开户支行" required name="openingBranch">
					<uni-easyinput v-model="valiFormData.openingBranch" placeholder="请输入开户支行" />
				</uni-forms-item>
				<uni-forms-item label="银行预留号码" required name="reservedNumber">
					<uni-easyinput v-model="valiFormData.reservedNumber" placeholder="请输入银行预留号码" />
				</uni-forms-item>
			</uni-forms>
		</view>
		<view class="addBtn" @click="submit()">
			提交银行卡
		</view>
	</view>
</template>

<script>
	import {
		createDoctorBank,
	} from '@/api/user'
	export default {
		data() {
			return {
				valiFormData: {},
				rules: {
					openingBank: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					openingBranch: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					reservedNumber: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}]
					},
					bankAccount: {
						rules: [{
							required: true,
							errorMessage: '不能为空'
						}, {
							format: 'number',
							errorMessage: '只能输入数字'
						}]
					}
				},
			}
		},
		onShow() {
			let that = this
			uni.$on('prescriptionId', function(data) {
				console.log("监听到事件来自返回的参数：", data);
				if (data) {
					that.getDoctorPrescription(data)
				}
			})
		},
		methods: {
			submit() {
				this.$refs.valiForm.validate().then(res => {
					uni.showLoading({
						title: '提交中',
						mask: true
					})
					createDoctorBank(this.valiFormData).then(res => {
						setTimeout(() => {
							uni.hideLoading()
							uni.$emit('show', true)
							//需要定时执行的代码
							uni.navigateBack({
								delta: 1, //返回层数，2则上上页
							})
						}, 200)
						
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},


		}
	}
</script>

<style lang="less" scoped>
	.info {
		padding: 30rpx;
		margin-top: 30rpx;
		background-color: #fff;

		/deep/.is-input-border {
			border: none;
		}
	}

	.addBtn {
		width: 649rpx;
		height: 100rpx;
		background: #3B6CFE;
		border-radius: 50rpx;
		font-weight: 500;
		font-size: 28rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 100rpx;
		position: fixed;
		bottom: 99rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>